package com.qf.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.mapper.DtsAdminMapper;
import com.qf.pojo.DtsAdmin;
import com.qf.service.DtsAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


@Service
public class DtsAdminServiceImpl implements DtsAdminService {

    @Autowired
    private DtsAdminMapper dtsAdminMapper;

    @Override
    public DtsAdmin queryAdminByUsername(String username) {

        QueryWrapper<DtsAdmin> wrapper = new QueryWrapper<>();
        wrapper.eq("username", username);
        wrapper.eq("deleted", false);
        DtsAdmin dtsAdmins = dtsAdminMapper.selectOne(wrapper);
        return dtsAdmins;
    }

    @Override
    public DtsAdmin create(DtsAdmin dtsAdmin) {

        dtsAdmin.setLastLoginTime(new Date());
        dtsAdmin.setDeleted(false);
        dtsAdmin.setAddTime(new Date());
        dtsAdmin.setUpdateTime(new Date());

        dtsAdminMapper.insert(dtsAdmin);

        return dtsAdmin;
    }

    @Override
    public void updateAdmin(DtsAdmin dtsAdmin) {
        dtsAdminMapper.updateById(dtsAdmin);
    }


}
